﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using PloobsEngine.Components;

namespace PloobsEngine.Features
{
    public class PloobsConsole : BasicComponent
    {
        // Find the center of the string
        Vector2 FontOrigin = new Vector2(10, 10);
       
        private Dictionary<string, ConsoleVar> atributes;
        SpriteFont consoletext;
        SpriteBatch batch;
        private EngineStuff es;
        private bool initialized;

        public PloobsConsole(EngineStuff game)
        {
            atributes = new Dictionary<string, ConsoleVar>();
            this.es = game;
            initialized = false;

        }
        public override void Initialize()
        {
            initialized = true;
            batch = new SpriteBatch(EngineStuff.GraphicsDevice);
            consoletext = EngineStuff.InternalContentManager.GetAsset<SpriteFont>("ConsoleFont");

            GraphVar.gd = EngineStuff.GraphicsDevice;
            ConstantVar.batch= batch;
            ConstantVar.font = consoletext;

            base.Initialize();
        }

        public override void AfterDraw(GameTime gt, Matrix activeView, Matrix activeProjection)
        {

            if (!initialized)
                return;
            FontOrigin = new Vector2(10, 10);
           
            // Draw the Title
            batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            batch.DrawString(consoletext, "Ploobs Console", FontOrigin, Color.Yellow);
            FontOrigin += new Vector2(0, 20);
            batch.End();

            
            foreach (KeyValuePair<string, ConsoleVar> item in atributes)
            {                                                             
                if (item.Value is ConstantVar)
                {
                   // FontOrigin=item.Value.Draw(FontOrigin + new Vector2(output.Length * 10, 0));
                }
                else
                {
                    item.Value.Draw(FontOrigin);
                }
            }           
            
        }

        //public override void Update(GameTime gt)
        //{
        //    base.Update(gt);
        //}

        public override ComponentType ComponentType
        {
            get { return ComponentType.POS_DRAWABLE; }
        }

        public static readonly String MyName = "PloobsConsole";
        public override string getMyName()
        {
            return MyName;
        }

        public void UpdateAtribute(string name, ConsoleVar value)
        {
            atributes[name] = value;
        }



    }



}